<?php

class Zend_View_Helper_Productnameforseo extends Zend_View_Helper_Abstract {

    protected $_keyword;
    protected $_country;
    protected $_language;

    /*
     * This helper makes seo products names
     *
     *
     */

    public function productnameforseo($type, $id) {
        $session = new Zend_Session_Namespace('GrandMarnier');
        $this->_language = $session->userLanguage;
        $this->_country = $session->country;
        if ($type == "DRINK") {
            return $this->getNameForDrink($id);
        } elseif ($type == "PRODUCT") {
            return $this->getNameForProduct($id);
        } elseif ($type == "DESSERT") {
            return $this->getNameForDessert($id);
        }
    }

    private function getNameForDrink($id) {
        $cocktails = new Application_Model_DbTable_Cocktail();
        $cocktails->setLanguage($this->_language);
        $drinkRealName = $cocktails->getCocktailName($id);
        return $this->prepareSEOString($drinkRealName);
    }

    private function getNameForProduct($id) {
        $cocktails = new Application_Model_DbTable_Product();
        $cocktails->setLanguage($this->_language);
        $productRealName = $cocktails->getProductName($id);
        return $this->prepareSEOString($productRealName);
    }

    private function getNameForDessert($id) {
        $cocktails = new Application_Model_DbTable_Desert();
        $cocktails->setLanguage($this->_language);
        $dessertRealName = $cocktails->getDessertName($id);
        return $this->prepareSEOString($dessertRealName);
    }
    
    private function prepareSEOString($string) {
        $search0 = " ";
        $replace0 = "-";
        $search1 = "®";
        $search1a = "'";
        $replace1 = "";
        $search = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u");
        $replace = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u");
        $drinkRealNameSeo = str_replace($search, $replace, $string);
        $drinkRealNameSeo = str_replace($search0, $replace0, $drinkRealNameSeo);
        $drinkRealNameSeo = str_replace($search1a, $replace1, $drinkRealNameSeo);
        $drinkRealNameSeo = str_replace($search1, $replace1, $drinkRealNameSeo);
        return strtolower($drinkRealNameSeo);
    }

    // The default representation of the greeting. Let's be nice, by default.
    public function __toString() {
        return "";
    }

}

#echo  $this->translatex('PRODUCT_HISTORY_WQ');
?>